package com.yxw.springmvc.test;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * Created by hp on 2016/10/12.
 */
public class LockTest1 {

    public static int i = 0;

    private static final ExecutorService pool = Executors.newFixedThreadPool(10);
    public static void main(String[] args) {
        for(int i = 0;i < 1000 ;i++){
            pool.execute(new K());
        }

    }

    static class P implements Runnable{
        @Override
        public void run() {
            System.out.println(i++);
        }
    }

    static class T implements Runnable{
        @Override
        public void run() {
            Lock lock = new ReentrantLock();
            lock.lock();
            try{
                System.out.println(i++);
            }finally {
                lock.unlock();
            }

        }
    }

    static class K implements Runnable{
        @Override
        public void run() {
            synchronized (this){
                System.out.println(i++);
            }

        }
    }
}
